package com.wjjun.databinding;

import android.databinding.BindingAdapter;
import android.databinding.ObservableList;

import com.wjjun.customview.views.GlideImageLoader;
import com.youth.banner.Banner;
import com.youth.banner.listener.OnBannerListener;
import com.youth.banner.loader.ImageLoader;

/**
 * banner
 * Created by 67535 on 2018/4/29.
 */
public class BannerAdapter {

    @BindingAdapter(value = {"items"}, requireAll = false)
    public static void banner(Banner banner, ObservableList items) {
        banner.setImages(items);
        banner.start();
    }

    @BindingAdapter(value = {"start"})
    public static void bannerStart(Banner banner, boolean isStart) {
        if (isStart) {
            banner.startAutoPlay();
        } else {
            banner.stopAutoPlay();
        }
    }

    @BindingAdapter(value = {"isAutoPlay"}, requireAll = false)
    public static void bannerSetting(Banner banner, boolean isAutoPlay) {
        banner.isAutoPlay(isAutoPlay);
    }

    @BindingAdapter(value = {"indicatorGravity", "bannerStyle"}, requireAll = false)
    public static void bannerIndicator(Banner banner, int indicatorGravity, int style) {
        banner.setBannerStyle(style);
        banner.setIndicatorGravity(indicatorGravity);
    }

    @BindingAdapter(value = {"imageLoader"}, requireAll = false)
    public static void bannerImageLoader(Banner banner, ImageLoader imageLoader) {
        if (imageLoader != null) {
            banner.setImageLoader(imageLoader);
        } else {
            banner.setImageLoader(new GlideImageLoader());
        }
    }

    @BindingAdapter(value = {"bannerListener"})
    public static void bannerListener(Banner banner, OnBannerListener listener) {
        banner.setOnBannerListener(listener);
    }

}
